import numpy as np
import matplotlib.pyplot as plt
import os

'''
list_temp = []
for root, dirs, files in os.walk("."):
    for filename in files:
        list_temp.append(filename)

kw = ['Angle']

filelist = []
for items in list_temp:
    for ele in kw:
        if ele in items:
            filelist.append(items)

ang = []
for i in range(len(filelist)):
    a = np.loadtxt(filelist[i]) 
    ang.append(a)

np.savetxt('ang_all.txt',ang)
'''
### same as cat all

ang1 = np.loadtxt('type1/ang_type1.txt')
ang2 = np.loadtxt('type2/ang_type2.txt')

bin_size= 0.2
min_edge = 0.
max_edge = 40.
bin_list = np.arange(min_edge, max_edge, bin_size)
Xs1 = np.arange(0.15,39.9,0.2)
Ys1 = np.histogram(ang1,bin_list)[0]
Xs1 = np.insert(Xs1,0,0)
Ys1 = np.insert(Ys1,0,0)

Xs2 = np.arange(0.15,39.9,0.2)
Ys2 = np.histogram(ang2,bin_list)[0]
Xs2 = np.insert(Xs2,0,0)
Ys2 = np.insert(Ys2,0,0)

save1 = np.zeros([])
np.savetxt('dist_type1.txt',np.array([Xs1,Ys1]).T)
np.savetxt('dist_type2.txt',np.array([Xs2,Ys2]).T)

plt.plot(Xs1,Ys1)
plt.plot(Xs2,Ys2)
plt.xlim(0,30)
plt.savefig('AngleDistribution.png',format='png',dpi=300,bbox_inches='tight')
plt.show()
